/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package damagecalculator;

import java.io.*;

/**
 *
 * @author Casal
 */
public class XMLCreator {

    public static void main(String args[]) {
        try {

            String type = "attack".replace(" ", "_");

            BufferedWriter out = new BufferedWriter(new FileWriter("src/damagecalculator/info.xml"));

            BufferedReader in = new BufferedReader(new FileReader("src/damagecalculator/info.txt"));
            String strLine;
            //Read File Line By Line
            out.write("<" + type + ">\n");
            int count = 1;
            while ((strLine = in.readLine()) != null) {
                if (!strLine.equals("")) {
                    if (count == 1) {
                        out.write("<name>" + strLine + "</name>\n");
                    } else if (count == 2) {
                        out.write("<tier>" + strLine + "</tier>\n");
                    } else if (count == 3) {
                        out.write("<price>" + strLine + "</price>\n");
                    } else if (count == 4) {
                        out.write("<description>" + strLine + "</description>\n");
                        out.write("\n");
                        count = 0;
                    }
                    count++;
                }
            }
            out.write("</" + type + ">");
            //Close the input stream
            out.close();
            in.close();
        } catch (IOException e) {//Catch exception if any
            System.err.println("Error: " + e.getMessage());
        }
    }
}
